{extend name='./_content'}

{block name='mid'}
<div class="">
    <div class="container">
    	<!-- 工具栏 -->
    	<div id="tableToolbar">
    		<button type="button" class="btn btn-success" onclick="view.fun();">查看</button>
    		<input type="text" name="search" id="search" class="form-control pull-right" placeholder="回车搜索" style="width: 200px;">
    	</div>	
    	<!-- 表格主体-->
    	<table id="table">
    	</table>
    	<!-- 表格数据处理（未完待续） -->
    	<script type="text/javascript">
    		$(function () {
    			view.init();
    		});
    		var view = {
    			table:null,//表格对象
    			dataUrl:'/index/city/tree',//数据加载地址
    			delUrl:'',//删除数据地址
    			selectedData:null,//选中的数据,
    			id:0,//操作数据的主键
    			dicts:{
    				has_child:[],//有无子节点字典
    			},
    			defaultColumns:function () {
                    var that = this;
    				//表头数据列
    				return [
    					{field: 'selectItem', checkbox: true},
    					{field:'name',title:'名称',formatter:function (argument) {
    						//console.log(argument);
    						return argument;
    					}},
                        {field:'full_name',title:'全称',align:'center'},
    					{field:'pname',title:'父级',align:'center',formatter:function (arg) {
                                if(arg == null){
                                    return '无父级';
                                }
                                return arg;
                            }},
                        {field:'has_child',title:'是否有子节点',formatter:function (val) {
                                return that.get_dict_value(that.dicts.has_child,val);
                        }}
    				];
    			},
    			init:function () {
    				var that = this;
    				that.table = $('#table').bootstrapTreeTable({
    					id: 'id',// 选取记录返回的值
                        code: 'id',// 用于设置父子关系
                        parentCode: 'pid',// 用于设置父子关系
                        rootCodeValue: "",//设置根节点code值----可指定根节点，默认为null,"",0,"0"
                        type: 'get',//请求数据的ajax类型
                        url: that.dataUrl,   //请求数据的ajax的url
                        ajaxParams: {}, //请求数据的ajax的data属性
                        expandColumn: 1,//在哪一列上面显示展开按钮,从0开始
                        striped: true,   //是否各行渐变色
                        expandAll: true,  //是否全部展开
                        columns: this.defaultColumns(),//列数组
                        toolbar: "#tableToolbar",//顶部工具条
                        height: 650,//默认高度
                        responseHandler:function (argument) {
                        	that.dicts.has_child = argument.dicts.has_child;
                        	console.log(argument);
                        	return argument;
                        },
                        clickToSelect:false,//点击行选中
                        expanderExpandedClass:'glyphicon  glyphicon-triangle-bottom',
                        expanderCollapsedClass:'glyphicon glyphicon-triangle-right'
    				})
    				this.initEvent();
    				$('#search').on('change',this.search);
    			},
    			initEvent:function(){
    				
    			},
    			fun:function(){
    				//getSelections:获取选中行
    				var obj = this.table.bootstrapTreeTable('getSelections');
    				console.log(obj);
    			},
    			search:function () {
    				view.table.bootstrapTreeTable('refresh',{
    					searchText:$('#search').val()
    				});
    			},
    			get_dict_value:function (obj,val) {
    				for (var i = 0; i < obj.length; i++) {
    					if (obj[i].value === val) {
    						return obj[i].name;
    					}
    				}
    				return val;
    			}
    		}
    	</script>
    </div>
</div>
{/block}